//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Resource Application Block
//===============================================================================

using System;
using System.Windows.Forms;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;
using EntLibContrib.Resource.Properties;

namespace EntLibContrib.Resource.Configuration.Design
{
	/// <summary>
	/// This class adds commands to the context menus of the nodes in the
	/// Resource Application Block node hierarchy.
	/// </summary>
	public class ResourceCommandRegistrar : CommandRegistrar
	{
		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="T:ResourceCommandRegistrar"/> class.
		/// </summary>
		/// <param name="serviceProvider">The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</param>
		public ResourceCommandRegistrar (IServiceProvider serviceProvider) : base(serviceProvider)
		{
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// Register the commands.
		/// </summary>
		public override void Register ()
		{
			AddResourceSettingsCommand();
			AddDefaultCommands(typeof(ResourceSettingsNode));

			AddResourceManagerCommand();
			AddDefaultCommands(typeof(ResourceManagerNode));

			AddCustomResourceManagerCommand();
			AddDefaultCommands(typeof(CustomResourceManagerNode));

			AddCustomResourceProviderCommand();
			AddGenerateStronglyTypedResourcesCommand(typeof(CustomResourceProviderNode));
			AddDefaultCommands(typeof(CustomResourceProviderNode));

			AddAssemblyResourceProviderCommand();
			AddGenerateStronglyTypedResourcesCommand(typeof(AssemblyResourceProviderNode));
			AddDefaultCommands(typeof(AssemblyResourceProviderNode));

			AddBinaryResourceProviderCommand();
			AddGenerateStronglyTypedResourcesCommand(typeof(BinaryResourceProviderNode));
			AddDefaultCommands(typeof(BinaryResourceProviderNode));

			AddXmlResourceProviderCommand();
			AddGenerateStronglyTypedResourcesCommand(typeof(XmlResourceProviderNode));
			AddDefaultCommands(typeof(XmlResourceProviderNode));
		}
		#endregion

		#region Private Methods
		private void AddResourceSettingsCommand ()
		{
			ConfigurationUICommand cmd = ConfigurationUICommand.CreateSingleUICommand(ServiceProvider,
																																								InternalResources.ResourceSettingsUICommandText,
																																								InternalResources.ResourceSettingsUICommandLongText,
																																								new AddResourceSettingsNodeCommand(ServiceProvider),
																																								typeof(ResourceSettingsNode));
			AddUICommand(cmd, typeof(ConfigurationApplicationNode));
		}

		private void AddResourceManagerCommand()
		{
			AddMultipleChildNodeCommand(InternalResources.ResourceManagerUICommandText,
																	InternalResources.ResourceManagerUICommandLongText,
																	typeof(ResourceManagerNode),
																	typeof(ResourceManagerCollectionNode));
		}

		private void AddCustomResourceManagerCommand()
		{
			AddMultipleChildNodeCommand(InternalResources.CustomResourceManagerUICommandText,
																	InternalResources.CustomResourceManagerUICommandLongText,
																	typeof(CustomResourceManagerNode),
																	typeof(ResourceManagerCollectionNode));
		}

		private void AddCustomResourceProviderCommand()
		{
			AddSingleChildNodeCommand(InternalResources.CustomResourceProviderUICommandText,
																InternalResources.CustomResourceProviderUICommandLongText,
																typeof(CustomResourceProviderNode),
																typeof(ResourceProviderBaseNode),
																typeof(ResourceManagerNode));
		}

		private void AddAssemblyResourceProviderCommand ()
		{
			AddSingleChildNodeCommand(InternalResources.AssemblyResourceProviderUICommandText,
																InternalResources.AssemblyResourceProviderUICommandLongText,
																typeof(AssemblyResourceProviderNode),
																typeof(ResourceProviderBaseNode),
																typeof(ResourceManagerNode));
		}

		private void AddBinaryResourceProviderCommand()
		{
			AddSingleChildNodeCommand(InternalResources.BinaryResourceProviderUICommandText,
																InternalResources.BinaryResourceProviderUICommandLongText,
																typeof(BinaryResourceProviderNode),
																typeof(ResourceProviderBaseNode),
																typeof(ResourceManagerNode));
		}

		private void AddXmlResourceProviderCommand()
		{
			AddSingleChildNodeCommand(InternalResources.XmlResourceProviderUICommandText,
																InternalResources.XmlResourceProviderUICommandLongText,
																typeof(XmlResourceProviderNode),
																typeof(ResourceProviderBaseNode),
																typeof(ResourceManagerNode));
		}

		private void AddGenerateStronglyTypedResourcesCommand(Type resourceProviderNodeType)
		{
			ConfigurationUICommand command = new ConfigurationUICommand(ServiceProvider,
																																	InternalResources.GenerateStronglyTypedResourcesUICommandText,
																																	InternalResources.GenerateStronglyTypedResourcesUICommandLongText,
																																	CommandState.Enabled,
																																	new GenerateStronglyTypedResourcesNodeCommand(ServiceProvider),
																																	Shortcut.None,
																																	InsertionPoint.Action,
																																	null);
			AddUICommand(command, resourceProviderNodeType);
			command.Dispose();
		}
		#endregion
	}
}